#include <cstdio>
using namespace std;
#define MAXN 50
#define Num 9
int v[MAXN];
int d[MAXN][2] ;//0--->+ 1---->-

int main()
{
	freopen("zigbagdata.in", "r", stdin);//重定向输入流
    //freopen("zigbagjdata.out", "w", stdout);//重定向输出流
    d[0][0]=1;
    d[0][1]=1;
    int n;
    int min ,max;
    while(scanf("%d", &n) != EOF){
    	printf("n:%d",n);
    	for(int i=0;i<n;i++) 
    	{
    		scanf("%d",&v[i]);
    		if( Num == n)
    		{
    			printf("%d,",v[i]);
    		}
    	}	
    	printf("\n");
        for (int i =1;i<n;i++)
        {
        	min = i;
        	max = i;
        	for(int j=i-1;j>=0;j--)
        	{
        		if (v[j]<v[i])
        		{
        			min = j;
        			break;
        		}
        	}
        	for(int j=i-1;j>=0;j--)
        	{
        		if (v[j]>v[i])
        		{
        			max = j;
        			break;
        		}	
        	}
        	if( Num == n)
    		{
    			printf("min = %d,max = %d\n",min,max);
    		}
        	
    		if(min <i)
        		d[i][0] = (((d[min][1]+1)>d[i-1][0])?(d[min][1]+1):d[i-1][0]);
        	else 
        		d[i][0] = 1; 
        	
        	if  (max <i)
        		d[i][1] = (((d[max][0]+1)>d[i-1][1])?(d[max][0]+1):d[i-1][1]);
        	else 
        		d[i][1] = 1;
        	if( Num == n)
    		{
    			printf("d[%d][0] = %d,d[%d][1] = %d\n",i,d[i][0],i,d[i][1]);
    		}
        	
        }
    	if (n<=2)
    	{
    		printf("%d\n",n);
    	}
    	else 
    	{
    		int maxN= (d[n-1][0]>d[n-1][1])?d[n-1][0]:d[n-1][1];
    		printf("%d\n",maxN);
    	}
    }

    fclose(stdin);
    //fclose(stdout);
    return 0;
}